package mapper;

import com.sqsf.javabean.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    List<User> selectAll();
    //之前在进行多个参数传递时 只能使用mybatis提供的参数名称
    //可以使用对应 注解 @Param进行自定义参数绑定
    User selectByUsernameAndPassword(@Param("username") String username,@Param("password") String password);
    //mybatis注解可以简化mapper的配置 甚至可以不书写mapper

    @Select("select * from user where uid=#{uid}")
    User selectByUid(int uid);

    @Insert("insert into user (username,password,phone)values(#{username},#{password},#{phone})")
    int insertUser(User user);

    @Delete("delete from user where uid=#{uid}")
    int deleteByUid(int uid);

    @Update("update user set password=#{password} where uid=#{uid}")
    int updatePasswordByUid(@Param("uid") int uid,@Param("password") String password);

    @Select("select uid,username uname,password pwd,phone tel from user")
    @Results(id = "u",value = {
            @Result(id = true,column = "uname",property = "username"),
            @Result(column = "pwd",property = "password"),
            @Result(column = "tel",property = "phone"),
    })
    List<User> selectAllUser();


    @Select("select uid,username uname,password pwd,phone tel from user")
    @ResultMap("u")
    List<User> selectAllUser1();
}